﻿using LxCore;
using System;
using System.Collections.ObjectModel;
using System.Numerics;
using System.Windows.Media.Media3D;

namespace LxCFD
{
    class MonitorPanelVM : BindableBase
    {
        public MonitorPanelVM()
        {
            CreateMonitor = new DelegateCommand(() =>
            {
                var m = MonitorCenter.CreateMonitor();
                SelMonitor = m;
            });
            DeleteMonitor = new DelegateCommand(() =>
            {
                int id = MonitorCenter.UserMonitors.IndexOf(SelMonitor);
                if (id < 0) return;
                MonitorCenter.RemoveMonitorAt(id);
            });
        }
        public MonitorCenter MonitorCenter { get => LxSim.Sim.Monitors; }
        public ConditionCenter MeshSet { get; } = LxSim.Sim.Conditions;

        private UserMonitor _SelMonitor;
        public UserMonitor SelMonitor
        {
            get { return _SelMonitor; }
            set
            {
                _SelMonitor = value;
                RaisePropertyChanged(nameof(SelMonitor));
                ConditionCenter.CurrentMonitor = value.ID;
                foreach (var zs in MeshSet.ZoneConds)
                {
                    zs.InnerCond.IsMonitorSel = zs.InnerCond.IsMonitorSel;
                }
                if (SelZoneSet != null)
                {
                    foreach (var bs in SelZoneSet.BoundConds)
                    {
                        bs.IsMonitorSel = bs.IsMonitorSel;
                    }
                }
            }
        }
        private ZoneCond _SelZoneSet;
        public ZoneCond SelZoneSet
        {
            get { return _SelZoneSet; }
            set { _SelZoneSet = value; RaisePropertyChanged(nameof(SelZoneSet)); }
        }
        private BoundCond _SelBoundSet;
        public BoundCond SelBoundSet
        {
            get { return _SelBoundSet; }
            set { _SelBoundSet = value; RaisePropertyChanged(nameof(SelBoundSet)); }
        }
        public DelegateCommand CreateMonitor { get; set; }
        public DelegateCommand DeleteMonitor { get; set; }
        private StatisticTypes[] _StatisticTypes = Enum.GetValues<StatisticTypes>();
        public StatisticTypes[] StatisticTypes
        {
            get => _StatisticTypes;
            set { _StatisticTypes = value; RaisePropertyChanged(nameof(StatisticTypes)); }
        }
        private ScalarFieldTypes[] _ScalarFieldTypes = Enum.GetValues<ScalarFieldTypes>();
        public ScalarFieldTypes[] ScalarFieldTypes
        {
            get { return _ScalarFieldTypes; }
            set { _ScalarFieldTypes = value; RaisePropertyChanged(nameof(ScalarFieldTypes)); }
        }
        private MonitorTrigerTypes[] _MonitorTrigerTypes = Enum.GetValues<MonitorTrigerTypes>();
        public MonitorTrigerTypes[] MonitorTrigerTypes
        {
            get => _MonitorTrigerTypes;
            set { _MonitorTrigerTypes = value; RaisePropertyChanged(nameof(MonitorTrigerTypes)); }
        }
    }
}
